package hash.jcl.map.leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * Set集合解决宝石与石头问题
 * @author yuisama
 * @date 2021/12/29 17:03
 **/
public class Num771 {
    public int numJewelsInStones(String jewels, String stones) {
        // 先使用set集合存储所有的jewels
        Set<Character> jewelSet = new HashSet<>();
        for (int i = 0; i < jewels.length(); i++) {
            jewelSet.add(jewels.charAt(i));
        }
        // 遍历stones的同时看jewel的Set
        int ret = 0;
        for (int i = 0; i < stones.length(); i++) {
            if (jewelSet.contains(stones.charAt(i))) {
                ret ++;
            }
        }
        return ret;
    }
}